﻿<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel="stylesheet" type="text/css" href="<%=path%>/js/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=path%>/js/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="<%=path%>/demo/demo.css">
	<link rel="stylesheet" type="text/css" href="<%=path%>/css/coun.css"/>
	<script type="text/javascript" src="<%=path%>/js/jquery-1.8.3.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/template.js"></script>
	<script type="text/javascript" src="<%=path%>/js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="<%=path%>/js/plugins/jquery.datagrid.js"></script>
	<script type="text/javascript">
		

				$(function(){
				/* 	loadUser(); */
					loadTable();
					loadsettle();
					
				var datedtd =getNowFormatDate();
				
				$('#dd').datebox('setValue',datedtd );
				});

				
				
				function getNowFormatDate() {
				    var date = new Date();
				    var seperator1 = "-";
				    var seperator2 = ":";
				    var month = date.getMonth() + 1;
				    var strDate = date.getDate();
				    if (month >= 1 && month <= 9) {
				        month = "0" + month;
				    }
				    if (strDate >= 0 && strDate <= 9) {
				        strDate = "0" + strDate;
				    }
				    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
				           
				    return currentdate;
				}
				
				
				
				function loadUser(){
					$.ajax({
						type:"GET",
				    	async: false,
				   	 	url:"<%=path %>/main/get/customer",
				   		data :null,
				   		dataType: "json",
				    	success:function(data){
				    	
				    		var memArchise=data.data;
	
				      		var beans = {			
								list : memArchise
				      		};
							var html = template('memberList', beans);
							document.getElementById('memberNames').innerHTML =html;	
				    				    		
					    	}
					});
				}
						
				function loadTable(){
	
					$.extend($.fn.validatebox.defaults.rules, {    
						length: { validator: function (value, param) {
							
						if(value<=1){
							if((value + '').indexOf('.') != -1){
				            	   var len = $.trim(value).length;
					               return len >= param[0] && len <= param[1];
				            	}
							}
			            },
			                message: "格式错误，请输入正确的折扣率"
			            }
					});  


					
					var ds =[
				{

				"ystype": "1",
				"ysname": "应收"
				},
				{
					"ystype": "0",
					"ysname": "应付"
				}
				];
					
					var as="";
					var xiaofeishuju ="";
					
						$.ajax({
							type:"GET",
					 		async: false,
							url:'<%=path%>/main/get/subinfo',
							dateType:'json',
							data:null,
							success:function(data){
								var result = eval('(' + data + ')');
								as=result.data;
							
								}
							});
						
						$.ajax({
							type:"GET",
					    	async: false,
					   	 	url:"<%=path %>/main/get/localxiaofei",
					   		data :{"cropid":<%=session.getAttribute("cropid")%>},
					   		dataType: "json",
					    	success:function(data){
					    						    		
					    		xiaofeishuju = data.data;		    		
						    	
					    	}
						});
						
						

					$('#tt').datagrid({
						
						width:1116,
	        			height:250,
						rownumbers:true,
						selectOnCheck: true,
					    checkOnSelect: true,
						title:'',	
						columns:[[
						{field:'id',title:'序号',width:190,checkbox:true},
			            {  
			                field: 'xiaofei',  
			                title: '消费大类',  //拥有远程数据库
			                width: 75,  
			                formatter: function(value) {  
			                    for (var i = 0; i < xiaofeishuju.length; i++) {  
			                        if (xiaofeishuju[i].consumeclass == value){ 
			                        	
			                        	return xiaofeishuju[i].consumeclass
			                        };  
			                    }  
			                    return value;  
			                },  
			                editor: {  
			                    type: 'combobox',  
			                    options: {  
			                        valueField: 'consumeclass',  
			                        textField: 'consumeclass',  
			                        data: xiaofeishuju,  
			                        required: true,
			                        onSelect:function(rowIndex, rowData){
			                  			
			                        	var row = $("#tt").datagrid('getSelected');
			                        	var rindex = $("#tt").datagrid('getRowIndex', row);
			                   
			                        	var ed = $("#tt").datagrid('getEditor', {
			                                index: rindex,
			                                field: 'xiaofei'
			                            });
			                        	
		
			                        	 var s = $(ed.target).combobox('getText');
			                        	
			                        	$.ajax({
			                				type:"GET",
			                		 		async: false,
			                				url:'<%=path%>/main/get/localzixiaofei',
			                				dateType:'json',
			                				data:{"iname":s},
			                				success:function(data){
			                					
			                					var result = eval('(' + data + ')');
			                				
			                					
			                					var editor = $("#tt").datagrid("getEditor",{index:rindex,field:'xiangmu'});
			                					$(editor.target).combobox("loadData",result.data);
			                			
			                					}
			                				});
			                        	}
			                    }  
			                }  
			            },
			            {  
			                field: 'xiangmu',  
			                title: '项目',  
			                width: 75,  
			                formatter: function(value) {  
			                    for (var i = 0; i < xiaofeishuju.length; i++) {  
			                        if (xiaofeishuju[i].code == value){ 
			                        	
			                        	return xiaofeishuju[i].codename
			                        };  
			                    }  
			                    return value;  
			                },  
			                editor: {  
			                    type: 'combobox',  
			                    options: {  
			                        valueField: 'projecttype',  
			                        textField: 'projecttype',  
			                        data: xiaofeishuju,  
			                        required: true
			                    }  
			                }  
			            },
			            {field:'xmmingxi',title:'项目明细',width:75,editor: { type: 'text', options: { required: true } }},
			            {field:'shoushudc1',title:'手术医师',width:75,editor: { type: 'text', options: { required: true } }},
			            {field:'shoushudc2',title:'配台医师',width:65,editor: { type: 'text', options: { required: true } }},
			            {field:'shoushudc3',title:'非手术医师',width:75,editor: { type: 'text', options: { required: true } }},
			            {field:'shoushudc4',title:'医师助手',width:65,editor: { type: 'text', options: { required: true } }},
            	        {field:'biaojia',title:'标价',width:55,editor: { type: 'validatebox', options: { required: true} }},
            	        {field:'shuliang',title:'数量',width:55,
            	        	editor: { type: 'validatebox', options: { required: true,
            	        							
            	        		} 
            	       		 }
            	        },
            	        {field:'zhekou',title:'折扣率',width:55,editor: { type: 'validatebox',options:{
            	        	validType:['zhekou','length[1,4]']
            	        }}},
            	        {field:'youhui',title:'优惠金额',width:65,editor: { type: 'validatebox'}},
            	        {field:'zhehoupr',title:'实际消费金额',width:85,editor: { type: 'numberbox',options:{
            	        	precision:"2" ,max:"99999.99",size:"8" ,maxlength:"8"
            	        }}},
            	        {field:'fssbz',title:'非手术备注',width:75,editor: { type: 'text', options: { required: true } }},	
            	        {field:'beizhu',title:'备注',width:70,editor: { type: 'text', options: { required: true } }},	
				        {field:'action',title:'操作',width:90,align:'center',
			                formatter:function(value,row,index){
			                    if (row.editing){
			                        var s = '<a onclick="saverow(this)">保存</a> ';
			                        var c = '<a onclick="cancelrow(this)">取消</a>';
			                        return s+c;
			                    } else {
			                        var e = '<a onclick="editrow(this)">编辑</a> ';
			                        var d = '<a onclick="deleterow(this)">删除</a>';
			                        return e+d;
			                    }
			                }
			            }
						          ]],
						  
						          
						          onBeforeEdit:function(index,row){
							            row.editing = true;
							            updateActions(index);
							        },
							        onAfterEdit:function(index,row){
							            row.editing = false;
							            updateActions(index);
							        },
							        onCancelEdit:function(index,row){
							            row.editing = false;
							            updateActions(index);
							        }
						 
					});	
				

				}
				function updateActions(index){
				    $('#tt').datagrid('updateRow',{
				        index: index,
				        row:{}
				    });
				}
				
				function getRowIndex(target){
				    var tr = $(target).closest('tr.datagrid-row');
				    return parseInt(tr.attr('datagrid-row-index'));
				}
				function editrow(target){
				    $('#tt').datagrid('beginEdit', getRowIndex(target));
					
				    var row = $('#tt').datagrid('getSelected');
				    var index = $('#tt').datagrid('getRowIndex', row);
				    setEditing(index);  
				}
				function deleterow(target){
				    $.messager.confirm('','确定删除？',function(r){
				        if (r){
				            $('#tt').datagrid('deleteRow', getRowIndex(target));
				        }
				    });
				}
				function saverow(target){
				    $('#tt').datagrid('endEdit', getRowIndex(target));
				}
				function cancelrow(target){
				    $('#tt').datagrid('cancelEdit', getRowIndex(target));
				}
				
				function insert(){
					
					$('#tt').datagrid('appendRow', {
						
					});
					var index = $("#tt").datagrid('getRows').length-1;
					
					if(index==0){
						
					}else{
						$("#tt").datagrid("unselectRow",index-1);
					}
					
					$('#tt').datagrid('selectRow',index);
					$('#tt').datagrid('beginEdit',index);
					          
                	  setEditing(index);  
					
				}
				
				function setEditing(rowIndex){   
					
					var arr=[];
					
					var editors = $('#tt').datagrid('getEditors', rowIndex);   
				    var priceEditor = editors[7];   //价格
				    var amountEditor = editors[8];   //数量
				    var zkEditor = editors[9];		//折扣率
			
				    var yhjine = editors[10];		//优惠金额
				    var zhEditor =editors[11];		//折后金额
				    priceEditor.target.bind('change', function(){   
				        calculate();   
				    });   
				    amountEditor.target.bind('change', function(){   
				        calculate();   
				    });
				    zkEditor.target.bind('change', function(){   
				        calculate();   
				    }); 
				    yhjine.target.bind('change', function(){   
				        calculate();   
				    }); 
				    
				    function calculate(){  
				    	
				    	var price=priceEditor.target.val();//价格
				        var amount=amountEditor.target.val();//数量
				        var zkl =zkEditor.target.val();//折扣率
				        var yh = yhjine.target.val();//优惠金额
				        
				    	
				        if(zkl!=0&&yh!=0){
				        	alert("折扣率和优惠金额只能输一项");
				        }else{
				        
				        if(zkl==0&&yh==0){
				    		var cost = price* amount;
				    		$(zhEditor.target).numberbox('setValue',cost);
				    		$(yhjine.target).val(0);
				    	}else{
				    	
				    	   if(zkl!=0&&yh==0){
				    		var cost = price* amount*zkl;
				  
							$(zhEditor.target).numberbox('setValue',cost);
							
				    	   }
							if(yh!=0&&zkl==0){
						
					    		var cost = price* amount-yh;
					    						    			
					    		$(zhEditor.target).numberbox('setValue',cost);
					    	
								}				    	   
				    		}
				    	}   
				    }    
				    
				} 
				function toDecimal(value){
					 var val = Number(value);
						   if (!isNaN(val)) {//判断是否是非数值
							 
						      if((val + '').indexOf('.') != -1){
						    	  
						    	
								val =parseFloat(val);
									    
									    
						       } 
						    }
					  return  val;    
				}
//====================================================================================
	</script>
	<script>

	var psj="";
	var fs="";
	var websj="";
	var scbsj="";
	var mzsj="";
	var other="";
	 $(function(){	
	    $('#tt1').datagrid({
	        rownumbers:true,
	        width:924,
	        height:150,
	       
	        checkOnSelect: true,
	        columns:[[
	            {field:'id',title:'序号',width:60,checkbox: true},
	            {field:'xczx',title:'现场咨询',width:100,editor: { type: 'text', options: { required: true } }},
	            {field:'phonezx',title:'电话咨询',width:100,editor: { type: 'text', options: { required: true }}},
	            {field:'webzx',title:'网络咨询',width:100,editor: { type: 'text', options: { required: true } }},
	            {field:'scb',title:'市场部',width:100,editor: { type: 'text', options: { required: true } }},
	            {field:'mznurse',title:'门诊护士',width:100,editor: { type: 'text', options: { required: true } }},
	            {field:'otherpp',title:'其他部门人员',width:100,editor: { type: 'text', options: { required: true } }},
	            {field:'hydw',title:'会员单位',width:80,editor: { type: 'text' }},
	            {field:'chuku',title:'出库单',width:80,editor: { type: 'text' }},
	            {field:'action',title:'操作',width:90,align:'center',
	                formatter:function(value,row,index){
	                    if (row.editing){
	                        var s = '<a  onclick="saverowb(this)">保存</a> ';
	                        var c = '<a  onclick="cancelrowb(this)">取消</a>';
	                        return s+c;
	                    } else {
	                        var e = '<a  onclick="editrowb(this)">编辑</a> ';
	                        var d = '<a  onclick="deleterowb(this)">删除</a>';
	                        return e+d;
	                    }
	                }
	            }
	        ]],
	        onBeforeEdit:function(index,row){
	            row.editing = true;
	            updateActionsb(index);
	        },
	        onAfterEdit:function(index,row){
	            row.editing = false;
	            updateActionsb(index);
	        },
	        onCancelEdit:function(index,row){
	            row.editing = false;
	            updateActionsb(index);
	        }
	    });
	});
	function updateActionsb(index){
	    $('#tt1').datagrid('updateRow',{
	        index: index,
	        row:{}
	    });
	}
	
	function getRowIndexb(target){
	    var tr = $(target).closest('tr.datagrid-row');
	    return parseInt(tr.attr('datagrid-row-index'));
	}
	function editrowb(target){
	    $('#tt1').datagrid('beginEdit', getRowIndexb(target));
	}
	function deleterowb(target){
	    $.messager.confirm('','删除确定?',function(r){
	        if (r){
	            $('#tt1').datagrid('deleteRow', getRowIndexb(target));
	        }
	    });
	}
	function saverowb(target){
	    $('#tt1').datagrid('endEdit', getRowIndexb(target));
	}
	function cancelrowb(target){
	    $('#tt1').datagrid('cancelEdit', getRowIndexb(target));
	}
	function insertb(){

		$('#tt1').datagrid('appendRow', {
	
		});

		var index = $("#tt1").datagrid('getRows').length-1;
		
		if(index==0){
			
		}else{
			$("#tt1").datagrid("unselectRow",index-1);
		}
				
		$('#tt1').datagrid('selectRow',index);

		$('#tt1').datagrid('beginEdit',index);	
	}
//===================================================================================
	</script>
	
	<script>
			
	function loadsettle(){
		var cs="";
		$.ajax({
			type:"GET",
	 		async: false,
			url:'<%=path%>/main/get/localsettles',
			dateType:'json',
			data:{"cropid":<%=session.getAttribute("cropid")%>},
			success:function(data){
				var result = eval('(' + data + ')');
				cs=result.data;
				}
		});
		
	    $('#tt2').datagrid({
	        rownumbers:true,
	        width:411,
	        height:140,

	        checkOnSelect: true,
	        columns:[[
	           {field:'id',title:'序号',width:60,checkbox:true},
	 	       {  
	                field: 'settlement',  
	                title: '结算方式',  
	                width: 70,  	          
	                editor: {  
	                    type: 'combobox',  
	                    options: {  
	                        valueField: 'settlement',  
	                        textField: 'settlement',  
	                        data: cs,  
	                        required: true,
	                    }  
	                }  
	            }, 
	            {field:'mingxi',title:'明细',width:60,editor: { type: 'text', options: { required: true } }},
	            {field:'jine',title:'金额',width:60,editor: { type: 'numberbox', options:{required: true,
    	        	precision:"2" ,max:"99999.99",size:"8" ,maxlength:"8"
    	        } }},
	            {field:'beizhu',title:'结算备注',width:60,editor: { type: 'text', options: { required: true } }},
	            {field:'action',title:'操作',width:70,align:'center',
	                formatter:function(value,row,index){
	                    if (row.editing){
	                        var s = '<a  onclick="saverowc(this)">保存</a> ';
	                        var c = '<a  onclick="cancelrowc(this)">取消</a>';
	                        return s+c;
	                    } else {
	                        var e = '<a  onclick="editrowc(this)">编辑</a> ';
	                        var d = '<a  onclick="deleterowc(this)">删除</a>';
	                        return e+d;
	                    }
	                }
	            }
	        ]],
	        onBeforeEdit:function(index,row){
	            row.editing = true;
	            updateActionsc(index);
	        },
	        onAfterEdit:function(index,row){
	            row.editing = false;
	            updateActionsc(index);
	        },
	        onCancelEdit:function(index,row){
	            row.editing = false;
	            updateActionsc(index);
	        },
	        onEndEdit:function(rowIndex, rowData, changes){
		      
		        
		    }
	    });
	}
//===================================================================================
	function updateActionsc(index){
	    $('#tt2').datagrid('updateRow',{
	        index: index,
	        row:{}
	    });
	}
	
	function getRowIndexc(target){
	    var tr = $(target).closest('tr.datagrid-row');
	    return parseInt(tr.attr('datagrid-row-index'));
	}
	function editrowc(target){
	    $('#tt2').datagrid('beginEdit', getRowIndexb(target));
	}
	function deleterowc(target){
	    $.messager.confirm('','确定删除?',function(r){
	        if (r){
	            $('#tt2').datagrid('deleteRow', getRowIndexb(target));
	        }
	    });
	}
	function saverowc(target){
	    $('#tt2').datagrid('endEdit', getRowIndexb(target));
	}
	function cancelrowc(target){
	    $('#tt2').datagrid('cancelEdit', getRowIndexb(target));
	}
	function insertC(){

		$('#tt2').datagrid('appendRow', {
		
		});
		
		var index = $("#tt2").datagrid('getRows').length-1;
		
		if(index==0){
			
		}else{
			$("#tt2").datagrid("unselectRow",index-1);
		}
		$('#tt2').datagrid('selectRow',index);
		$('#tt2').datagrid('beginEdit',index);
	}
//===================================================================================
	</script>
		
	<script>
	
	$(function(){
		 //自定义1个combogrid编辑器
		 $.extend($.fn.datagrid.defaults.editors, {
		
			    combogrid: {			
			        init: function(container, options){			
			            var input = $('<input id="cc" type="text" class="datagrid-editable-input">').appendTo(container);
			           	
			            input.combogrid(options);		
			            return input;			
			        },
			        
			        destroy: function(target){			
			            $(target).combogrid('destroy');		
			        },
		
			        getValue: function(target){			
			            return $(target).combogrid('getValue');		
			        },
			
			        setValue: function(target, value){		
			            $(target).combogrid('setValue', value);			
			        },
			        setValues: function(target, values){		
			            $(target).combogrid('setValues', values);			
			        },
			
			        resize: function(target, width){		
			            $(target).combogrid('resize',width);			
			        }
			
			    }
			
			});   

		
		
		var es =[
	{

	"ystype": "1",
	"ysname": "应收"
	},
	{
		"ystype": "0",
		"ysname": "应付"
	}
	];
		
		var  gssj="";
				
		$('#tt3').datagrid({
			
			width:463,
			height:140,
			url:'.json',

			rownumbers:true,
			selectOnCheck: true,
		    checkOnSelect: true,
			title:'',	
			columns:[[
			{field:'id',title:'序号',width:190,checkbox:true},
	         {  
                field: 'buytype',  
                title: '类型(其他应收应付)',  
                width: 130,  
           
                editor: {  
                    type: 'combobox',  
                    options: {  
                        valueField: 'ysname',  
                        textField: 'ysname',  
                        data: es,  
                        required: true,
                        onSelect:function(rowIndex, rowData){
			                  
                        	var row = $("#tt3").datagrid('getSelected');
                        	var rindex = $("#tt3").datagrid('getRowIndex', row);
                   
                        	var ed1 = $("#tt3").datagrid('getEditor', {
                                index: rindex,
                                field: 'buytype'
                            });
                   
                        	  var s = $(ed1.target).combobox('getValue');
                        
                        	  //本地proinfo表
                        	$.ajax({
                				type:"GET",
                		 		async: false,
                				url:'<%=path%>/rm/crp',
                				dateType:'json',
                				data:{"buytype":s,"cropid":<%=session.getAttribute("cropid")%>},
                				success:function(data){
                				
                				 var result = eval('(' + data + ')');	
                				
                				 var editor = $("#tt3").datagrid("getEditor",{index:rindex,field:'productid'});
                				$(editor.target).combobox("loadData",result.data); 
                			
                					}
                				});
                        	}
                    }  
                }  
            },
            {  
                field: 'productid',  
                title: '公司',  
                width: 70,  
               
                editor: {  
                    type: 'combobox',  
                    options: {  
                        valueField: 'corp',  
                        textField: 'corp',                         
                        required: true,
                        
                        onSelect:function(rowIndex, rowData){
			                  
                        	var row = $("#tt3").datagrid('getSelected');
                        	var rindex = $("#tt3").datagrid('getRowIndex', row);
                   
                        	var ed = $("#tt3").datagrid('getEditor', {
                                index: rindex,
                                field: 'productid'
                            });
                        	 gssj="";
                        	 gssj = $(ed.target).combobox('getText');
                    
                        	}
                    } 
                }  
            },
            //{field:'productid',title:'公司',name:'productId',width:100}, 
            	{field:'jines',title:'金额',width:70,editor: { type: 'numberbox', options:{required: true,
    	        	precision:"2" ,max:"99999.99",size:"8" ,maxlength:"8"
    	        } }},
	            {field:'action',title:'操作',width:70,align:'center',
	                formatter:function(value,row,index){
	                    if (row.editing){
	                        var s = '<a  onclick="saverowd(this)">保存</a> ';
	                        var c = '<a  onclick="cancelrowd(this)">取消</a>';
	                        return s+c;
	                    } else {
	                        var e = '<a  onclick="editrowd(this)">编辑</a> ';
	                        var d = '<a  onclick="deleterowd(this)">删除</a>';
	                        return e+d;
	                    }
	                }
	            }
	        ]],
	        onBeforeEdit:function(index,row){
	        	
	            row.editing = true;
	            updateActionsd(index);
	        },
	        onAfterEdit:function(index,row){
	            row.editing = false;
	            updateActionsd(index);
	            
	        },
	        onCancelEdit:function(index,row){
	        	
	            row.editing = false;
	            updateActionsd(index);

	        },
	        onEndEdit:function(rowIndex, rowData, changes){
	        /* 	var fs= $('#cc').combogrid('getValues'); */
	        	
	        	rowData.productid = gssj;
	        	
	        }
	    });
		
	});
	function updateActionsd(index){
	    $('#tt3').datagrid('updateRow',{
	        index: index,
	        row:{}
	    });
	}
	
	function getRowIndexd(target){
	    var tr = $(target).closest('tr.datagrid-row');
	    return parseInt(tr.attr('datagrid-row-index'));
	}
	function editrowd(target){
	    $('#tt3').datagrid('beginEdit', getRowIndexd(target));
	}
	function deleterowd(target){
	    $.messager.confirm('','确定删除?',function(r){
	        if (r){
	            $('#tt3').datagrid('deleteRow', getRowIndexd(target));
	        }
	    });
	}
	function saverowd(target){
	    $('#tt3').datagrid('endEdit', getRowIndexd(target));  
	}
	function cancelrowd(target){
	    $('#tt3').datagrid('cancelEdit', getRowIndexb(target));
	}
	function insertd(){

		$('#tt3').datagrid('appendRow', {
	
		});
		
		var index = $("#tt3").datagrid('getRows').length-1;
		
		if(index==0){
			
		}else{
			$("#tt3").datagrid("unselectRow",index-1);
		}

		$('#tt3').datagrid('selectRow',index);
		$('#tt3').datagrid('beginEdit',index);
	}
	</script>
	<script>
	//新加1
	function addNum(num1,num2){
		var sq1,sq2,m;
		try{sq1=num1.toString().split(".")[1].length;} catch(e){sq1=0;}
		try{sq2=num2.toString().split(".")[1].length;} catch(e){sq2=0;}

		m=Math.pow(10,Math.max(sq1,sq2));
		return ( num1 * m + num2 * m ) / m;
		}
	
	
		function saveshuju(){
	
			var dd = $('#dd').datebox('getValue'); 
			var danju = document.getElementById('danju').value;
			var lsh = document.getElementById('lsh').value;
			var fph =  document.getElementById('fph').value;
			
		
			
			var name = $("#memberNames").textbox("getValue");
			var phone = document.getElementById('phone').value;
			var banka = $('#banka').datebox('getValue'); 
			var youhuis = document.getElementById('youhui').value;
			
			var yuyue = $('#yuyue').datebox('getValue'); 
			
			var fptt = document.getElementById('fptt').value;
		
	
			 //获取tt表里面的数据
			 var g21="";
			 var g22="";
			 var g23="";
			 var g24="";
			 var g25="";
			 var g26="";
			 var g27="";
			 var g28="";
			 var g29="";
			 var g210="";
			 var g211="";
			 var g212="";
			 var g213="";
			 var g214="";
				var checkedItems = $('#tt').datagrid('getChecked');
				
				var  price=0;
				
				var column = 1; 
				
				
				var s1 ="";
				var s2 ="";
				var s3 ="";
				var s4 ="";
				var s5 ="";
				var s6 ="";
				var s7 ="";
				var s8 ="";
				var s9 ="";
				var s10 ="";
				var s11 ="";
				var s12 ="";
				var s13 ="";
				var s14 ="";
				
				var guodu1="";
				var guodu2="";
				var guodu3="";
				var guodu4="";
				var guodu5="";
				var guodu6="";
				var guodu7="";
				var guodu8="";
				var guodu11="";
				var guodu111="";
				
				$.each(checkedItems, function(index, item){
					
					//新加2
					price=addNum(price,Number(item.zhehoupr));
				
					s1+=s1==""?item.xiaofei:","+item.xiaofei;
					s2+=s2==""?item.xiangmu:","+item.xiangmu;
					
					if(item.xmmingxi==""){
						guodu1="1"
					}else{
						guodu1=item.xmmingxi
					}
					s3+=guodu1+","
					
					
					
					if(item.shoushudc1==""){
						guodu2="1"
					}else{
						guodu2=item.shoushudc1
					}
					s4+=guodu2+","
					
					
					if(item.shoushudc2==""){
						guodu3="1"
					}else{
						guodu3=item.shoushudc2
					}
					s5+=guodu3+","
					
					
					if(item.shoushudc3==""){
						guodu4="1"
					}else{
						guodu4=item.shoushudc3
					}
					s6+=guodu4+","
					
					
					if(item.shoushudc4==""){
						guodu5="1"
					}else{
						guodu5=item.shoushudc4
					}
					s7+=guodu5+","
					
				
					s8+=s8==""?item.biaojia:","+item.biaojia;
					s9+=s9==""?item.shuliang:","+item.shuliang;
				
		

					if(item.zhekou==""){
						guodu6="1"
					}else{
						guodu6=item.zhekou
					}
					s10+=guodu6+","
					
					if(item.zhehoupr==""){
						guodu7="1"
					}else{
						guodu7=item.zhehoupr
					}
					s11+=guodu7+","
					
					
					if(item.beizhu==""){
						guodu8="1"
					}else{
						guodu8=item.beizhu
					}
					s12+=guodu8+","
					
					
					if(item.youhui==""){
						guodu11="1"
					}else{
						guodu11=item.youhui
					}
					s13+=guodu11+","
					
					
					if(item.fssbz==""){
						guodu111="1"
					}else{
						guodu111=item.fssbz
					}
					s14+=guodu111+","

					});
				
					
				
				g21=s1;
				g22=s2;
				g23=s3;
				g24=s4;
				g25=s5;
				g26=s6;
				g27=s7;
				g28=s8;
				g29=s9;
				g210=s10;
				g211=s11;
				g212=s12;
				g213=s13;
				g214=s14;
				console.log(g21+"||"+g22+"||"+g23+"||"+g24+"||"+g25+"||"+g26+"||"+g27+"||"+g28+"||"+g29+"||"+g210+"||"+g211+"||"+g212+"||"+g213+"$$$$$$$"+"||"+g214);
				console.log(price+"##");
				toDecimal(price);
				console.log(price);
				$("#sum").val(price); 
			
			
			
			//获取tt1表里面的数据
			var g1="";
			var g2="";
			var g3="";
			var g4="";
			var g5="";
			var g6="";
			var hy="";
			var chuku ="";
			var checkedItems = $('#tt1').datagrid('getChecked');
/* 			if(checkedItems[0]==undefined){
				g1="1,";
				g2="1,";
				g3="1,";
				g4="1,";
				g5="1,";
				g6="1,";
				hy="1,";
			}else{ */
				var ss1 ="";
				var ss2 ="";
				var ss3 ="";
				var ss4 ="";
				var ss5 ="";
				var ss6 ="";
				var ss7 ="";
				var sss8="";
				
				var guodus1="";
				var guodus2="";
				var guodus3="";
				var guodus4="";
				var guodus5="";
				var guodus6="";
				var guodus7="";
				var guoduss8="";
				
				$.each(checkedItems, function(index, item){
					
					if(item.xczx==""){
						guodus1="1";
					}else{
						guodus1=item.xczx;
					}
					ss1+=guodus1+",";
				
					if(item.phonezx==""){
						guodus2="1";
					}else{
						guodus2=item.phonezx;
					}
					ss2+=guodus2+",";
					
					
					if(item.webzx==""){
						guodus3="1";
					}else{
						guodus3=item.webzx;
					}
					ss3+=guodus3+",";
					

					if(item.scb==""){
						guodus4="1";
					}else{
						guodus4=item.scb;
					}
					ss4+=guodus4+",";
					
					if(item.mznurse==""){
						guodus5="1";
					}else{
						guodus5=item.mznurse;
					}
					ss5+=guodus5+",";
					
					if(item.otherpp==""){
						guodus6="1";
					}else{
						guodus6=item.otherpp;
					}
					ss6+=guodus6+",";
					
					if(item.hydw==""){
						guodus7="1";
					}else{
						guodus7=item.hydw;
					}
					ss7+=guodus7+",";
					
					
					if(item.chuku==""){
						guoduss8="1";
					}else{
						guoduss8=item.chuku;
					}
					sss8+=guoduss8+",";
					
					
					});
				
				g1=ss1;
				g2=ss2;
				g3=ss3;
				g4=ss4;
				g5=ss5;
				g6=ss6;
				hy=ss7;
				chuku=sss8;
			
				
			//}	
			
			//获取tt2表格里面的数据
			var g31="";
			var g32="";
			var g33="";
			var g34="";
			
				var checkedItems = $('#tt2').datagrid('getChecked');
				var jine=0;
				if(checkedItems[0]==undefined){
					jine=0;
					g31="1,";
					g32="1,";
					g33="1,";
					g34="1,";
				}else{
	
				var s1 ="";
				var s2 ="";
				var s3 ="";
				var s4 ="";
				
				var guodu9="";
				var guodu10="";
				$.each(checkedItems, function(index, item){
					
					jine+=Number(item.jine);
			
					if(item.settlement=="服务项目"){
						jine-=Number(item.jine);
					}
					
					s1+=s1==""?item.settlement:","+item.settlement;
					
					
					
					if(item.mingxi==""){
						guodu9="1"
					}else{
						guodu9=item.mingxi
					}
					s2+=guodu9+","
					
				
				
					s3+=s3==""?item.jine:","+item.jine;
				
			
					if(item.beizhu==""){
						guodu10="1"
					}else{
						guodu10=item.beizhu
					}
					s4+=guodu10+","
			
				});
				console.log(jine);
					g31=s1;
					g32=s2;
					g33=s3;
					g34=s4;
				}
	

					//获取tt3表里面的数据
					 var g41="";
					 var g42="";
					 var g43="";
			
						var checkedItems = $('#tt3').datagrid('getChecked');
				
					
						
						var jines1=0;//应收金额
						var jines0=0;//应付金额
						if(checkedItems[0]==undefined){
							jines1=0;//应收金额
						    jines0=0;//应付金额
							g41="1,";
							g42="1,";
							g43="1,";
						}else{
						var s1="";
						var s2="";
						var s3="";
						
						var guduo12="";
						var guduo13="";
						var guduo14="";
						
		
	
						$.each(checkedItems, function(index, item){
							
						
							 if(item.buytype=="应付"){
								
								 jines0+=Number(item.jines);
								
							}
							if(item.buytype=="应收"){
								 jines1+=Number(item.jines);
							} 
							
							if(item.buytype==""){
								guodu11="1,"
							}else{
								guodu11=item.buytype
							}
							s1+=guodu11+","
							
							if(item.productid==""){
								guodu12="1,"
							}else{
								guodu12=item.productid
							}
							s2+=guodu12+","
						
							
							if(item.jines==""){
								guodu13="1,"
							}else{
								guodu13=item.jines
							}
							s3+=guodu13+","
									
					
						});
						
						g41=s1;
						g42=s2;
						g43=s3;
				
			
						}
	
		
			
	 	 	 if(dd==null||dd==""||name==null||name==""){
				
				alert("请完善数据!");
			}else{	
				
				if(g31.indexOf("服务项目") >=0 )  
				{  
					 $.ajax({
							type:"GET",
					    	async: false,
					    	contentType: "application/x-www-form-urlencoded; charset=utf-8", 
					   	 	url:"<%=path %>/lbs/save/billmain",
					   		data :{"dd":dd,"danju":danju,"lsh":lsh,"fph":fph,"name":name,"phone":phone,"banka":banka,"youhui":youhuis,"yuyue":yuyue,"chuku":chuku,"fptt":fptt,"g1":g1,"g2":g2,"g3":g3,"g4":g4,"g5":g5,"g6":g6,"hy":hy,"g21":g21,"g22":g22,"g23":g23,"g24":g24,"g25":g25,"g26":g26,"g27":g27,"g28":g28,"g29":g29,"g210":g210,"g211":g211,"g212":g212,"g213":g213,"g214":g214,"g31":g31,"g32":g32,"g33":g33,"g34":g34,"g41":g41,"g42":g42,"g43":g43},
					   		dataType: "json",
					    	success:function(data){
					    	
					    		console.log(data);
					    	
					    		var status = data.data;
					    		if(status=='插入成功'){
					    			alert("保存成功!");
					    			}
					    		if(status=='101'){
					    			alert("流水号重复，请检查!");
					    		}
					    		if(status=='102'){
					    			alert("消费大类表数据和现场咨询表数据不匹配!");
					    		}
								
						    }
							}); 
					
				}else{ 
				
				if(price+jines0==jine+jines1){								
 		 $.ajax({
							type:"GET",
					    	async: false,
					    	contentType: "application/x-www-form-urlencoded; charset=utf-8", 
					   	 	url:"<%=path %>/lbs/save/billmain",
					   		data :{"dd":dd,"danju":danju,"lsh":lsh,"fph":fph,"name":name,"phone":phone,"banka":banka,"youhui":youhuis,"yuyue":yuyue,"fptt":fptt,"g1":g1,"g2":g2,"g3":g3,"g4":g4,"g5":g5,"g6":g6,"hy":hy,"chuku":chuku,"g21":g21,"g22":g22,"g23":g23,"g24":g24,"g25":g25,"g26":g26,"g27":g27,"g28":g28,"g29":g29,"g210":g210,"g211":g211,"g212":g212,"g213":g213,"g214":g214,"g31":g31,"g32":g32,"g33":g33,"g34":g34,"g41":g41,"g42":g42,"g43":g43},
					   		dataType: "json",
					    	success:function(data){
					    	
					    		console.log(data);
					    	
					    		var status = data.data;
					    		if(status=='插入成功'){
					    			alert("保存成功!");
					    			}
					    		if(status=='101'){
					    			alert("流水号重复，请检查!");
					    		}
					    		if(status=='102'){
					    			alert("消费大类表数据和现场咨询表数据不匹配!");
					    		}
								
						    }
					   			
	
							});  
					}else{
						alert("价格不平，请重新计算");
					}
				}
			}  
		}
		
		function validatemobile(){
			var va =document.getElementById('phone').value;
			var telReg = !!va.match(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);
			//如果手机号码不能通过验证
			if(telReg == false){
			 alert("请输入正确手机号码!");
			}
		}
		
		function fangqi(){
			var r=confirm("确定放弃吗?"); 
			if(r==true){
				
				$.ajax({
					type:"GET",
			    	async: false,
			   	 	url:"<%=path%>/ls/fangqi",
			   		data :null,
			   		dataType: "json",
			    	success:function(data){
			      		
			      		var num = data.status
			      		
			      		if(num!=0){
			      			window.location.href="<%=path%>/ls/get/ls";
			      		
			      		}
			    	}
				});
				
				
			}
		}
	</script>
<style>
	  	.accountbox{
		width:1200px;
	}
	#div1{

		float: left;
	
	}	
		#div2{
		margin-left:  40px;  
		float: left;
	
	}
	.titbtn{
		width:550px;
	}	
</style>
<title>无标题文档</title>
</head>

<body>
<div class="accountbox">
<h2>账套名称</h2>
<div class="dateof">
<ul>
<li><label>日期 <span style="color:red">*</span></label><input id="dd" type="text" class="easyui-datebox" required="required"/></li>
<li><label>单据号</label><input id="danju" type="text" value="" /></li>
<li><label>流水号</label><input id="lsh" type="text" value="<%=session.getAttribute("lscode") %>" /></li>
<li><label>发票号</label><input id="fph" type="text" value="" /></li>
</ul>
</div>
<h3>收款单</h3>
<div class="customerName wrapbored">
 <ul>
  <li><label>顾客姓名<span style="color:red">*</span></label><input type="text" class="easyui-textbox" id="memberNames" required="required"/>
				<!-- <select id='memberNames'>
					<script type="text/html" id="memberList" name="memberList">
                   				<option value=""></option>
						{{each list as value index}}
								<option value="{{value.usercode}}">{{value.username}}</option>
						{{/each}}
                    </script>
				</select>-->
</li>
  <li><label>手机号码</label><input id="phone" type="text" value="" onblur="validatemobile()"/></li>
  <li><label>办卡时间</label><input id="banka" type="text" class="easyui-datebox"/></li>
  <li><label>优惠活动</label><input id="youhui" type="text" value="" /></li>

  <li><label>预约金时间</label><input id="yuyue" type="text" class="easyui-datebox" /></li>
  <!-- <li><label>出库单</label><input id="chuku" type="text" value=""/></li> -->
  <li><label>发票抬头</label><input id="fptt" type="text" value="" /></li>
 </ul>
</div>

<div class="scenebox1 wrapbored">
		<div style="margin-left:0px" id="dd1">
			<span><a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small" onclick="insert()">
				<span class="l-btn-left">
					<span class="l-btn-text">新增</span>
				</span>
			</a></span>
		</div>
		<table id="tt">
			
		</table>
	<div class="combined"><label>合计</label><input id="sum" type="text" value="" /></div>
</div>
<div class="scenebox2 wrapbored">
	<div style="margin-left:0px" id="dd1">
		<span>	<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small" onclick="insertb()">
				<span class="l-btn-left">
					<span class="l-btn-text">新增</span>
				</span>
			</a>
		</span>

	</div>
	
	<table id="tt1">
						
	</table>
		
</div>
<div class="wrapbored">
	<div id="div1">
	 	<div style="margin-left:0px" id="">
				<span><a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small" onclick="insertC()">
					<span class="l-btn-left">
						<span class="l-btn-text">新增</span>
					</span>
				</a></span>
					
		</div>
		<table id="tt2">
							
		</table>
	</div>
	
	<div id="div2">
		<div style="margin-left:0px" id="">
				<span><a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small" onclick="insertd()">
					<span class="l-btn-left">
						<span class="l-btn-text">新增</span>
					</span>
				</a></span>
			
		</div>

		<table id="tt3">
							
		</table>
	</div>
</div>		<!-- <span><a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small" onclick="baocun()">
				<span class="l-btn-left">
					<span class="l-btn-text">保存</span>
				</span>
			</a></span> -->
<div class="titbtn"><a href="<%=path%>/ls/get/ls">增加</a><a href="#" onclick="fangqi()">放弃</a>
				<span><a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small" onclick="saveshuju()">
				<span class="l-btn-left">
					<span class="l-btn-text">保存</span>
				</span>
			</a></span></div>
</div>
</body>
</html>
    